package com.aigou.admin.dao.impl;

import com.aigou.admin.utils.JDBCUtils;
import com.aigou.admin.dao.ShopCartDao;
import com.aigou.admin.entity.Receiving_address;
import com.aigou.admin.entity.ShopCart;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author: xsc_hunter
 * @Date: 2024/12/4) 下午3:47
 * @Version: 1.0
 */

@Repository
public class ShopCartDaoImpl implements ShopCartDao {
    @Override
    public Integer selectCount() {
        return JDBCUtils.executeCount("select count(*) from s_shop_cart");
    }

    @Override
    public List<ShopCart> selectShopCartByLimit(int start, int rows) {
        return JDBCUtils.executeQuery(ShopCart.class,"select * from s_shop_cart limit ?,?",start,rows);

    }

    @Override
    public List<ShopCart> selectAll() {
        return JDBCUtils.executeQuery(ShopCart.class, "select * from s_shop_cart");

    }

    @Override
    public ShopCart selectById(String id) {
        List<ShopCart> shopCarts = JDBCUtils.executeQuery(ShopCart.class, "select * from s_shop_cart where id = ? ",  id);
        if (shopCarts.isEmpty()) {
            return null;
        }
        return shopCarts.get(0);
    }

    @Override
    public Boolean insert(ShopCart shopCart) {
        int rows = JDBCUtils.executeUpdate("insert into s_shop_cart(id,cart_id,user_id) values(?,?,?)",
                shopCart.getId(),shopCart.getCart_id(),shopCart.getUser_id());
        return rows > 0;
    }

    @Override
    public Boolean update(ShopCart shopCart) {
        int rows = JDBCUtils.executeUpdate("update s_shop_cart set cart_id=?,user_id=? where id = ?",
                shopCart.getId(),shopCart.getCart_id(),shopCart.getUser_id());
        return rows > 0;
    }

    @Override
    public Boolean delete(String id) {
        int rows = JDBCUtils.executeUpdate("delete from s_shop_cart where id = ?", id);
        return rows >0;
    }
}
